/*****************************************************************
**                                                             	**
**  Copyright (C) 2004 Amlogic,Inc.                            	**
**  All rights reserved                                        	**
**        Filename : WinPeripheralDev.c /Project:AVOS		       **
**        Revision : 1.1                                       	**
**                                                             	**
*****************************************************************/
#include "../menu.h"
#include "WinPeripheralDevEvent.h"
#include "NetmenuSetupEvent.h"

INT32S WinPeripheralDevMsgProc_1080P(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return WinPeripheralDevOnShow(hwnd, lpParam) ;
    }
    return 0 ;
}

void SetWinPeripheralDevPalette_1080P(void)
{
    YUVENTRY mask_para[4] = {0,0,4095,4095};
    AWSetAlphaMask(0,4, mask_para);
    YUVENTRY palette_para[16] = {0x8000 | 16392,0x8000 | 18184,0x8000 | 18184,0x8000 | 16392,17592,18152,22116,19656,19992,18104,17673,17817,15864,15721,15912,16344};
    AWSetPalette(0,16, palette_para);
    return ;
}

void SetWinPeripheralDevPos_1080P(HWND* pControl, INT8U CurOsdSize)
{
    switch(CurOsdSize){
	case OsdSize1080p:
           RECT WindowRect1080p = {0,0,1920,1080};
            pControl->winrect = WindowRect1080p;
            CREATEWINDOWPARAM WindowPara1080p = {1,{{0,0,1920,1080},    {0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},    SetWinPeripheralDevPalette_1080P};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&WindowPara1080p);
            break ;
    }//end of switch
    return;
}

HWND *CreateControlWinPeripheralDev_1080P(HWND* pParent,INT8U CurOsdSize)
{
    HWND* pNewControl;
    switch(CurOsdSize){
	case OsdSize1080p:
            CREATEWINDOWPARAM window_para1080p = {1,{{0,0,1920,1080},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},SetWinPeripheralDevPalette_1080P};
            //Create Menu Window -- 1
            pNewControl = AWCreateWinControl("TWindow","WinPeripheralDev_1080P",WS_OVERLAPPEDWINDOW,
		                      0,0,1920,1080,NULL, (INT32S)&window_para1080p,WinPeripheralDevMsgProc_1080P) ;
            pNewControl->win_id = 0 ;
            break ;
    }//end of switch
            return pNewControl;
}

void SetWinConPeripheralDevPos_1080P(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    switch(CurOsdSize){
	case OsdSize1080p:
            pControl->winrect.top = pControl->parent->winrect.top + 290;
            pControl->winrect.left = pControl->parent->winrect.left + 680;
            pControl->winrect.width = 560;
            pControl->winrect.height = 550;
            pControl->draw_info_num = 2;
            RECT DrawRect1080p[2] = {
            {pControl->winrect.left + 10,pControl->winrect.top + 5,540,486},
            {pControl->winrect.left + 220,pControl->winrect.top + 498,300,36},
            };
            for(iLoop=0; iLoop < 2; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &DrawRect1080p[iLoop], sizeof(RECT));
            break ;
    }//end of switch
    return;
}

INT32S WinConPeripheralDevMsgProc_1080P(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return WinConPeripheralDevOnShow(hwnd, lpParam) ;
        case WM_PAINT:
            return WinConPeripheralDevOnPaint(hwnd, lpParam) ;
        case WM_KEYDOWN:
            return WinConPeripheralDevOnKeyPress(hwnd, lpParam) ;
        default:
            return WinConPeripheralDevOnOtherEvent(hwnd, msg_type, lpParam) ;
    }
    return 0 ;
}
 
HWND *CreateControlWinConPeripheralDev_1080P(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- WinConPeripheralDev
    HWND *pNewControl;
    switch(CurOsdSize){
	case OsdSize1080p:
            pNewControl = AWCreateWinControl("TControl","WinConPeripheralDev_1080P",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		                      270,120,400,360,pParent,0,WinConPeripheralDevMsgProc_1080P) ;
            pNewControl->win_id = 1 ;
            pNewControl->draw_info_num = 2;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO DrawDatas1080p[2] = {
                          {0,0,0,0,(INT32U)ICON_PC_CONNECT,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)0,DT_RESOURCE_STRING_DATA}};
            memcpy(pNewControl->draw_info,DrawDatas1080p, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            break ;
    }//end of switch
            return pNewControl;
}

HWND* CreateMenuWinPeripheralDev_1080P(void)
{
    HWND *pNewControl ;
    TWINDOWS *pWin;
    HWND *pWinPeripheralDev = CreateControlWinPeripheralDev_1080P(NULL,CurrentOsdSize);
    SetWinPeripheralDevPos_1080P(pWinPeripheralDev,CurrentOsdSize);

    pNewControl= CreateControlWinConPeripheralDev_1080P(pWinPeripheralDev,CurrentOsdSize);
    SetWinConPeripheralDevPos_1080P(pNewControl,CurrentOsdSize);

    pWin = (TWINDOWS *)pWinPeripheralDev;
    pWin->pFocusControl = AWFindWinCtrlByName("WinConPeripheralDev_1080P");
    return pWinPeripheralDev;
}

void WinResetWinPeripheralDevControlsPos_1080P(HWND *pControl, INT8U CurOsdSize)
{
    switch(pControl->win_id){
        case 0://WinPeripheralDev
            SetWinPeripheralDevPos_1080P(pControl,CurOsdSize) ;
            break ;
        case 1://WinConPeripheralDev
            SetWinConPeripheralDevPos_1080P(pControl,CurOsdSize) ;
            break ;
    }//end of switch
}
void WinResetWinPeripheralDevPos_1080P(HWND *pControl, INT8U CurOsdSize)
{
    HWND *pChildControl;
    if(pControl == NULL)
        pControl = AWFindWinCtrlByName("WinPeripheralDev_1080P");
    if(pControl == NULL) return ;

    WinResetWinPeripheralDevControlsPos_1080P(pControl, CurOsdSize) ;
    pChildControl = pControl->children ;
    while(pChildControl != NULL){
    	WinResetWinPeripheralDevPos_1080P(pChildControl, CurOsdSize) ;
    	pChildControl = pChildControl->siblings ;
	}
	return ;
}

